/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author user
 */
import java.awt.event.*;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Vector;
import javax.swing.*;
import javax.swing.table.DefaultTableModel;

public class csvTable {
   static DefaultTableModel dtm;
   static String[] tableData;
   static Vector rowData=new Vector();
     //Вектор, представляющий строку таблицы
   static Vector rows = new Vector();
     //Вектор векторов, хранящий всю таблицу
   static Vector columns = new Vector();
public static String readPage(String fileName, String strPage)
    throws Exception
   {
           String str="";

   InputStreamReader inputstream = null;
   try
    {
            inputstream = new InputStreamReader(new FileInputStream(fileName),"utf8");
             BufferedReader in = new BufferedReader(inputstream);

     while (((str = in.readLine()) != null))
       {
                  str=  str.replace(" CRLF", "");
                  tableData= str.split("\t");
                  rowData=new Vector();
             for(int i=0;i< tableData.length;i++)
             {
             //System.out.println(tableData[i]);
             rowData.add(tableData[i]);
             }
             rows.add(rowData);
       }


    }
      catch (IOException ex) {}
      return strPage;
   }
 public static Action action = new AbstractAction("Чтение данных из файла") {
       public void actionPerformed(ActionEvent evt) {
           rows.clear();
             try {
           String strPage = "";
               try {
                   strPage =
                           readPage("/home/user/EKB_console/Inf_ST_tel_po_ID/PS/out-1-ID.txt", strPage);
               } catch (Exception ex) {

               }
          dtm.fireTableDataChanged();

       } catch (Exception ex) {

       }
       }
   };

   private static void createAndShowGUI() {

       Vector row = new Vector();
       rows.add( row );

       columns.add ( "1" );
       columns.add ( "2" );
       columns.add ( "3" );
       columns.add ( "4" );
       columns.add ( "5" );
       columns.add ( "6" );
       dtm = new DefaultTableModel(rows, columns);
JFrame frame =
  new JFrame("Таблица из файла в JTable");
       frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
       JButton jb=new JButton(action);
       jb.setText("Прочитать из файла");
       Box box = new Box(BoxLayout.Y_AXIS);

       JTable jtb=new JTable(dtm);
        box.add(jb);
        box.add(jtb);
        frame.getContentPane().add(box);
        frame.setSize(333, 333);
        frame.setVisible(true);
   }

   public static void main(String[] args) {
       javax.swing.SwingUtilities.invokeLater(new Runnable() {
           public void run() {
               createAndShowGUI();
           }
       });
   }
}